<?php


namespace app\admin\controller;

use think\Controller;
use think\Db;

class User extends Base
{
    public function add()
    {

        if (request()->isAjax()) {
            $data = input('');

            $this->user_insert($data);

            $this->success('添加成功');
        } else {
            return $this->fetch();
        }


    }

    public function add2()
    {

        if (request()->isAjax()) {
            $data = $data2 = input('');
            if (!$data['phone']) {
                $this->error('请输入手机号');
            }
            $ret = Db::name('user')->where('phone', $data['phone'])->find();
            if ($ret) {
                $this->error('手机号已存在');
            }


            if (!$data['avatar']) {
                $this->error('请上传头像');
            }

            if (!$data['password']) {
                $this->error('请输入密码');
            }
            if (!$data['repassword']) {
                $this->error('请输入密码');
            }
            if (!$data['phone']) {
                $this->error('请输入联系方式');
            }
            if ($data['password'] != $data['repassword']) {
                $this->error('两次密码不一致');
            }

            $identity = $data2['identity'];

            foreach ($identity as $index => $item) {
                if ($index == 'pm') {
                    $data['is_pm'] = 1;
                }
                if ($index == 'qc') {

                    $data['is_qc'] = 1;

                }
                if ($index == 'worker') {
                    $data['worker'] = 1;
                }
            }


            unset($data['worker']);
            unset($data['identity']);
            unset($data['repassword']);
            unset($data['file']);
            $data['password'] = cmf_password($data['password']);
            // 开启事务
            Db::startTrans();

            $uid = Db::name('user')->insertGetId($data);


            $identity = $data2['identity'];
            foreach ($identity as $index => $item) {
                if ($index == 'worker') {
                    $flag = true;
                    $worker = $data2['worker'];
                    $worker['uid'] = $uid;

                    if (!$worker['gongzhong']) {
                        $msg = '请输入工种';
                        $flag = false;

                    }

                    if (!$worker['gongling']) {

                        $msg = '请输入工龄';
                        $flag = false;
                    }

                    if (!$worker['nianling']) {

                        $msg = '请输入年龄';
                        $flag = false;
                    }

                    if (!$worker['fuwushu']) {

                        $msg = '请输入服务人数';
                        $flag = false;

                    }

                    if (!$flag) {
                        Db::rollback();
                        $this->error($msg);
                    }

                    $worker['renzhenghao'] = "A" . (1000 + $uid) . rand(10, 99);
                    $worker['avatar2'] = $data['avatar'];

                    Db::name('user_worker')->insertGetId($worker);
                }
            }

            Db::commit();
            $this->success('添加成功');
        } else {
            return $this->fetch();
        }


    }

    /**
     * {
     * code: 0,
     * msg: "",
     * count: 1000,
     * data: []
     * }
     */
    public function index()
    {

//        dump($this->admin_id);die;
        if (request()->isAjax()) {
            $status[0] = '禁用';
            $status[1] = '正常';
            $page = input('page') ? input('page') : 1;
            $limit = input('limit') ? input('limit') : 10;

            $res = Db::name('user')->page($page, $limit)
                ->where('is_pm', '<>', 1)
                ->where('is_qc', '<>', 1)
                ->where('is_worker', '<>', 1)
                ->order('id', 'desc')
                ->select();
            $qiniu_config = cmf_get_option('qiniu');
            // 七牛样式处理
            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x60r/gravity/Center/crop/60x60/quality/100/interlace/0";
            foreach ($res as $index => $re) {
                $res[$index]['status2'] = $status[$re['status']];
                $res[$index]['avatar'] = $qiniu_config['domain'] . '/' . $re['avatar'] . $q_thumb;
                if (!$re['last_ip']) {
                    $res[$index]['last_ip'] = '无';
                }
                if ($re['last_time']) {
                    $res[$index]['last_time'] = date('Y-m-d H:i:s', $re['last_time']);
                } else {
                    $res[$index]['last_time'] = '无';
                }
            }

            return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
        } else {

            $count = Db::name('user')
                ->where('is_pm', '<>', 1)
                ->where('is_qc', '<>', 1)
                ->where('is_worker', '<>', 1)
                ->count();
            $this->assign('count', $count);

            return $this->fetch();
        }


    }

    public function user_search()
    {

        $status[0] = '禁用';
        $status[1] = '正常';
        $page = input('page') ? input('page') : 1;
        $limit = input('limit') ? input('limit') : 10;

        $key = trim(input('keyword'));
        if (!$key) {
            $this->error('没有内容');
        }

        $res = Db::name('user')->page($page, $limit)
            ->where('is_pm', '<>', 1)
            ->where('is_qc', '<>', 1)
            ->where('is_worker', '<>', 1)
            //搜索相关
            //参数绑定
            // ->where('id > :id AND name LIKE :name ', ['id' => 0, 'name' => 'thinkphp%'])
            ->where('phone LIKE :key1 OR truename LIKE :key ', ['key1' => "%$key%", 'key' => "%$key%"])
            ->select();
        $qiniu_config = cmf_get_option('qiniu');
        // 七牛样式处理
        $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/60x60/quality/100/interlace/0";
        foreach ($res as $index => $re) {
            $res[$index]['status2'] = $status[$re['status']];
            $res[$index]['avatar'] = $qiniu_config['domain'] . '/' . $re['avatar'] . $q_thumb;

        }
        //根据关键字返回 相应数据
        $total = Db::name('user')
            ->where('is_pm', '<>', 1)
            ->where('is_qc', '<>', 1)
            ->where('is_worker', '<>', 1)
            //搜索相关
            ->where('phone LIKE :key1 OR truename LIKE :key ', ['key1' => "%$key%", 'key' => "%$key%"])
            ->count();
        return json(['code' => 1, 'msg' => 'ok', 'total' => $total, 'data' => $res]);


    }


    public function edit()
    {

        if (request()->isAjax()) {
            $data = input('');
            $res = $this->user_base_update($data);
            if ($res === false) {
                $this->success('操作失败');
            }
            $this->success('操作成功');

        } else {
            $id = input('id');
            if (!$id) {
                $this->error('id 异常');
            }

            $qiniu_config = cmf_get_option('qiniu');
            // 七牛样式处理
            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";

            $res = Db::name('user')->where('id', $id)->find();
            $res['avatar2'] = $qiniu_config['domain'] . '/' . $res['avatar'] . $q_thumb;
            $this->assign('item', $res);
            return $this->fetch();
        }


    }


    // 项目经理
    public function pm()
    {

//        dump($this->admin_id);die;
        if (request()->isAjax()) {

            $res = $this->get_user_by_type('is_pm');

            return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
        } else {

            $count = Db::name('user')->where('is_pm', 1)->count();
            $this->assign('count', $count);

            return $this->fetch();
        }

    }


    public function pm_add()
    {

        if (request()->isAjax()) {
            $data = $data2 = input('');
            $this->user_insert($data, 'is_pm');
            $this->success('添加成功');
        } else {
            return $this->fetch();
        }


    }


    public function pm_edit()
    {

        if (request()->isAjax()) {
            $data = input('');
            $res = $this->user_base_update($data);
            if ($res === false) {
                $this->success('操作失败');
            }
            $this->success('操作成功');

        } else {
            $id = input('id');
            if (!$id) {
                $this->error('id 异常');
            }

            $qiniu_config = cmf_get_option('qiniu');
            // 七牛样式处理
            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";

            $res = Db::name('user')->where('id', $id)->find();
            $res['avatar2'] = $qiniu_config['domain'] . '/' . $res['avatar'] . $q_thumb;
            $this->assign('item', $res);
            return $this->fetch();
        }


    }


    // 质检员
    public function qc()
    {

//        dump($this->admin_id);die;
        if (request()->isAjax()) {

            $res = $this->get_user_by_type('is_qc');

            return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
        } else {

            $count = Db::name('user')->where('is_qc', 1)->count();
            $this->assign('count', $count);

            return $this->fetch();
        }

    }


    public function qc_add()
    {

        if (request()->isAjax()) {
            $data = $data2 = input('');
            $this->user_insert($data, 'is_qc');
            $this->success('添加成功');
        } else {
            return $this->fetch();
        }


    }

    public function qc_edit()
    {

        if (request()->isAjax()) {
            $data = input('');
            $res = $this->user_base_update($data);
            if ($res === false) {
                $this->success('操作失败');
            }
            $this->success('操作成功');

        } else {
            $id = input('id');
            if (!$id) {
                $this->error('id 异常');
            }

            $qiniu_config = cmf_get_option('qiniu');
            // 七牛样式处理
            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";

            $res = Db::name('user')->where('id', $id)->find();
            $res['avatar2'] = $qiniu_config['domain'] . '/' . $res['avatar'] . $q_thumb;
            $this->assign('item', $res);
            return $this->fetch();
        }


    }


    /**
     * 客户经理am
     * @return mixed|\think\response\Json
     */
    public function am()
    {

//        dump($this->admin_id);die;
        if (request()->isAjax()) {

            $res = $this->get_user_by_type('is_am');

            return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
        } else {

            $count = Db::name('user')->where('is_am', 1)->count();
            $this->assign('count', $count);

            return $this->fetch();
        }

    }


    public function am_add()
    {

        if (request()->isAjax()) {
            $data = $data2 = input('');
            $this->user_insert($data, 'is_am');
            $this->success('添加成功');
        } else {
            return $this->fetch();
        }


    }

    public function am_edit()
    {

        if (request()->isAjax()) {
            $data = input('');
            $res = $this->user_base_update($data);
            if ($res === false) {
                $this->success('操作失败');
            }
            $this->success('操作成功');

        } else {
            $id = input('id');
            if (!$id) {
                $this->error('id 异常');
            }

            $qiniu_config = cmf_get_option('qiniu');
            // 七牛样式处理
            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";

            $res = Db::name('user')->where('id', $id)->find();
            $res['avatar2'] = $qiniu_config['domain'] . '/' . $res['avatar'] . $q_thumb;
            $this->assign('item', $res);
            return $this->fetch();
        }


    }


    /**
     * 设计师
     * @return mixed|\think\response\Json
     */
    public function ds()
    {

//        dump($this->admin_id);die;
        if (request()->isAjax()) {

            $res = $this->get_user_by_type('is_ds');

            return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
        } else {

            $count = Db::name('user')->where('is_ds', 1)->count();
            $this->assign('count', $count);

            return $this->fetch();
        }

    }


    public function ds_add()
    {

        if (request()->isAjax()) {
            $data = $data2 = input('');
            $this->user_insert($data, 'is_ds');
            $this->success('添加成功');
        } else {
            return $this->fetch();
        }


    }

    public function ds_edit()
    {

        if (request()->isAjax()) {
            $data = input('');
            $res = $this->user_base_update($data);
            if ($res === false) {
                $this->success('操作失败');
            }
            $this->success('操作成功');

        } else {
            $id = input('id');
            if (!$id) {
                $this->error('id 异常');
            }

            $qiniu_config = cmf_get_option('qiniu');
            // 七牛样式处理
            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";

            $res = Db::name('user')->where('id', $id)->find();
            $res['avatar2'] = $qiniu_config['domain'] . '/' . $res['avatar'] . $q_thumb;
            $this->assign('item', $res);
            return $this->fetch();
        }


    }


    // 工人管理
    public function worker()
    {

//        dump($this->admin_id);die;
        if (request()->isAjax()) {
            $status[0] = '禁用';
            $status[1] = '正常';
            $page = input('page') ? input('page') : 1;
            $limit = input('limit') ? input('limit') : 10;

            $res = Db::name('user')->page($page, $limit)->where('is_worker', 1)->select();
            $qiniu_config = cmf_get_option('qiniu');
            // 七牛样式处理
            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/60x80/quality/100/interlace/0";
            $wk = Db::name('user_worker');
            foreach ($res as $index => $re) {
                $res[$index]['status2'] = $status[$re['status']];
                $res[$index]['avatar'] = $qiniu_config['domain'] . '/' . $re['avatar'] . $q_thumb;
                $res[$index]['worker'] = $wk->where('uid', $re['id'])->find();


            }

            return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
        } else {

            // $res=Db::name('user')->select();
            // foreach ($res as $index => $re) {
            //     Db::name('user')->where('id',$re['id'])->update(['truename'=>'代号'.rand(0000,9999)]);
            // }


            $count = Db::name('user')->where('is_worker', 1)->count();
            $this->assign('count', $count);

            return $this->fetch();
        }

    }


    public function worker_add()
    {
        if (request()->isAjax()) {
            $data = $data2 = input('');

            $data['is_worker'] = 1;
            $data['identity'] = 1;
            unset($data['worker']);

            // 开启事务
            Db::startTrans();

            $flag = true;

            $uid = $this->user_insert($data);
            if (!$uid) {
                $msg = '添加失败2';
                $flag = false;
            }


            $worker = $data2['worker'];
            $worker['uid'] = $uid;

            if (!$worker['gongzhong']) {
                $msg = '请输入工种';
                $flag = false;

            }

            if (!$worker['gongling']) {

                $msg = '请输入工龄';
                $flag = false;
            }

            if (!$worker['nianling']) {

                $msg = '请输入年龄';
                $flag = false;
            }

            if (!$worker['fuwushu']) {

                $msg = '请输入服务人数';
                $flag = false;

            }

            if (!$flag) {
                Db::rollback();
                $this->error($msg);
            }

            $worker['renzhenghao'] = "A" . (1000 + $uid) . rand(10, 99);
            $worker['avatar2'] = $data['avatar'];

            Db::name('user_worker')->insertGetId($worker);

            Db::commit();
            $this->success('添加成功');
        } else {
            return $this->fetch();
        }
    }


    public function worker_edit()
    {

        if (request()->isAjax()) {
            $data = input('');
            $worker = $data['worker'];
            unset($data['worker']);
            $res = $this->user_base_update($data);
            $worker['avatar2'] = $data['avatar'];
            Db::name('user_worker')->where('uid', $data['id'])->update($worker);

            if ($res === false) {
                $this->success('操作失败');
            }
            $this->success('操作成功');

        } else {
            $id = input('id');
            if (!$id) {
                $this->error('id 异常');
            }

            $qiniu_config = cmf_get_option('qiniu');
            // 七牛样式处理
            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";

            $res = Db::name('user')->where('id', $id)->find();
            $res['avatar2'] = $qiniu_config['domain'] . '/' . $res['avatar'] . $q_thumb;
            $this->assign('item', $res);


            $worker = Db::name('user_worker')->where('uid', $id)->find();
            $this->assign('worker', $worker);


            return $this->fetch();
        }


    }


    public function biz()
    {
//        dump($this->admin_id);die;
        if (request()->isAjax()) {
            $status[0] = '禁用';
            $status[1] = '正常';
            $page = input('page') ? input('page') : 1;
            $limit = input('limit') ? input('limit') : 10;

            $res = Db::name('user')->page($page, $limit)
                ->where('is_biz', 1)
                ->order('id', 'desc')
                ->select();
            $qiniu_config = cmf_get_option('qiniu');
            // 七牛样式处理
            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/60x80/quality/100/interlace/0";
            $wk = Db::name('user_biz');
            foreach ($res as $index => $re) {
                $res[$index]['status2'] = $status[$re['status']];

                $biz = $wk->where('uid', $re['id'])->find();
                $biz['shop_logo'] = $qiniu_config['domain'] . '/' . $biz['shop_logo'] . $q_thumb;
                $res[$index]['biz'] = $biz;


            }

            return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
        } else {

            $count = Db::name('user')->where('is_biz', 1)->count();
            $this->assign('count', $count);

            return $this->fetch();
        }
    }

    public function biz_add()
    {
        if (request()->isAjax()) {
            $data = $data2 = input('');
            $data['avatar'] = '/res/img/avatar.png';
            $data['is_biz'] = 1;
            $data['identity'] = 1;
            unset($data['biz']);

            // 开启事务
            Db::startTrans();

            $flag = true;

            $uid = $this->user_insert($data);
            if (!$uid) {
                $msg = '添加失败2';
                $flag = false;
            }


            $worker = $data2['biz'];
            $worker['uid'] = $uid;

            if (!$worker['address']) {
                $msg = '请输入地址';
                $flag = false;

            }

            if (!$worker['sheng']) {

                $msg = '请输入省份';
                $flag = false;
            }

            if (!$worker['shi']) {

                $msg = '请输入市';
                $flag = false;
            }

            if (!$worker['xian']) {

                $msg = '请输入区、县';
                $flag = false;

            }

            if (!$worker['shop_name']) {

                $msg = '请输入店名';
                $flag = false;

            }

            if (!$flag) {
                Db::rollback();
                $this->error($msg);
            }

            Db::name('user_biz')->insertGetId($worker);

            Db::commit();
            $this->success('添加成功');
        } else {
            return $this->fetch();
        }
    }

    public function biz_edit()
    {


        if (request()->isAjax()) {
            $data = input('');
            $worker = $data['biz'];
            unset($data['biz']);
            $res = $this->user_base_update($data);
            // $worker['avatar2'] = $data['avatar'];
            Db::name('user_biz')->where('uid', $data['id'])->update($worker);

            if ($res === false) {
                $this->success('操作失败');
            }
            $this->success('操作成功');

        } else {
            $id = input('id');
            if (!$id) {
                $this->error('id 异常');
            }


            $res = Db::name('user')->where('id', $id)->find();

            $this->assign('item', $this->set_array_default($res));

            $qiniu_config = cmf_get_option('qiniu');
            // 七牛样式处理
            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/quality/100/interlace/0";
            $biz = Db::name('user_biz')->where('uid', $id)->find();

            $biz['shop_logo2'] = $qiniu_config['domain'] . '/' . $biz['shop_logo'] . $q_thumb;


            $this->assign('biz', $this->set_array_default($biz));


            return $this->fetch();
        }

    }


    public function info()
    {

        $id = input('id');
        if (!$id) {
            $this->error('id 异常');
        }

        $info = Db::name('admin')
            ->find($id);
        $this->success('ok', '', $info);

    }


    public function del()
    {
        $data = input('');
        $ids = $data['ids'];

        if (!$ids) {
            $this->error('异常');
        }

        // $ids_str=implode(',',$ids);
        Db::name('user')->where('id', 'in', $ids)->delete();
        Db::name('user_worker')->where('uid', 'in', $ids)->delete();
        // $sql=Db::name('user')->getLastSql();
        // dump($sql);
        $this->success('操作成功');
    }


    //设置用户状态
    public function set_status()
    {
        $data = input('');
        $ids = $data['ids'];
        $status = $data['status'];

        if (!$ids) {
            $this->error('异常');
        }

        // $ids_str=implode(',',$ids);
        Db::name('user')->where('id', 'in', $ids)->update(['status' => $status]);
        // $sql=Db::name('user')->getLastSql();
        // dump($sql);
        $this->success('操作成功');


    }

    /**
     * 用户权限设置
     */
    public function user_auth()
    {

        if (request()->isPost()) {
            $data = input('');
            $id = $data['id'];
            if (!$id) {
                $this->error('no id');
            }


            if (!request()->has('role')) {
                $role['is_pm'] = 0;
                $role['is_am'] = 0;
                $role['is_qc'] = 0;
                $role['is_ds'] = 0;
            } else {
                $role = $data['role'];
            }

            Db::name('user')->where('id', $id)->update($role);
            $res = Db::name('user')->where('id', $id)
                ->field('is_pm,is_qc,is_am,is_ds')
                ->find();

            if ($res['is_pm']) {
                $res['is_pm2'] = true;
            } else {
                $res['is_pm2'] = false;
            }


            if ($res['is_qc']) {
                $res['is_qc2'] = true;
            } else {
                $res['is_qc2'] = false;
            }


            if ($res['is_am']) {
                $res['is_am2'] = true;
            } else {
                $res['is_am2'] = false;
            }


            if ($res['is_ds']) {
                $res['is_ds2'] = true;
            } else {
                $res['is_ds2'] = false;
            }


            $this->success('操作成功', '', $res);
        } else {
            return $this->fetch();
        }


    }

    /**
     * 基础查找
     * @return \think\response\Json
     */
    public function base_so()
    {
        $status[0] = '禁用';
        $status[1] = '正常';

        $key = trim(input('keyword'));
        if (!$key) {
            $this->error('没有内容');
        }

        $res = Db::name('user')
            //搜索相关
            //参数绑定
            // ->where('id > :id AND name LIKE :name ', ['id' => 0, 'name' => 'thinkphp%'])
            ->where('phone LIKE :key1 OR truename LIKE :key ', ['key1' => "%$key%", 'key' => "%$key%"])
            ->select();
        $qiniu_config = cmf_get_option('qiniu');
        // 七牛样式处理
        $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/60x60/quality/100/interlace/0";
        foreach ($res as $index => $re) {
            $res[$index]['status2'] = $status[$re['status']];
            $res[$index]['avatar'] = $qiniu_config['domain'] . '/' . $re['avatar'] . $q_thumb;
            if ($re['is_pm']) {
                $res[$index]['is_pm2'] = true;
            } else {
                $res[$index]['is_pm2'] = false;
            }


            if ($re['is_qc']) {
                $res[$index]['is_qc2'] = true;
            } else {
                $res[$index]['is_qc2'] = false;
            }


            if ($re['is_am']) {
                $res[$index]['is_am2'] = true;
            } else {
                $res[$index]['is_am2'] = false;
            }


            if ($re['is_ds']) {
                $res[$index]['is_ds2'] = true;
            } else {
                $res[$index]['is_ds2'] = false;
            }


        }

        return json(['code' => 1, 'msg' => 'ok', 'data' => $res]);
    }






    // {
    // "code": 1
    // ,"msg": ""
    // ,"data": {
    // "username": "贤心"
    // ,"sex": "男"
    // ,"role": 1
    // }
    // }

    public function get_session()
    {
        $data = [];
        $data['username'] = $this->admin_info['username'];
        return json(['code' => 1, 'data' => $data]);

    }


    private function user_base_update($data)
    {
        unset($data['file']);
        if ($data['password']) {
            $data['password'] = cmf_password($data['password']);
        } else {
            unset($data['password']);
        }


        if (!$data['id']) {
            $this->error('异常');
        }

        if (!$data['phone']) {
            $this->error('请输入联系方式');
        }

        $ret = Db::name('user')->where('id', '<>', $data['id'])
            ->where('phone', $data['phone'])
            ->find();
        if ($ret) {
            $this->error('手机号重复');
        }


        $res = Db::name('user')->where('id', $data['id'])->update($data);

        return $res;

    }


    private function user_insert($data, $type = false)
    {
        if (!$data['phone']) {
            $this->error('请输入手机号');
        }
        $ret = Db::name('user')->where('phone', $data['phone'])->find();
        if ($ret) {
            $this->error('手机号已存在');
        }


        if (!$data['avatar']) {
            $this->error('请上传头像');
        }

        if (!$data['password']) {
            $this->error('请输入密码');
        }
        if (!$data['repassword']) {
            $this->error('请输入密码');
        }
        if (!$data['phone']) {
            $this->error('请输入联系方式');
        }
        if ($data['password'] != $data['repassword']) {
            $this->error('两次密码不一致');
        }
        if ($type) {
            $data[$type] = 1;
        }


        unset($data['repassword']);
        unset($data['file']);
        $data['create_time'] = time();
        $data['password'] = cmf_password($data['password']);


        $uid = Db::name('user')->insertGetId($data);

        return $uid;

    }

    private function get_user_by_type($type)
    {
        $status[0] = '禁用';
        $status[1] = '正常';
        $page = input('page') ? input('page') : 1;
        $limit = input('limit') ? input('limit') : 10;

        $res = Db::name('user')->page($page, $limit)->where($type, 1)->select();
        $qiniu_config = cmf_get_option('qiniu');
        // 七牛样式处理
        $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x60r/gravity/Center/quality/100/interlace/0";
        foreach ($res as $index => $re) {
            $res[$index]['status2'] = $status[$re['status']];
            $res[$index]['avatar'] = $qiniu_config['domain'] . '/' . $re['avatar'] . $q_thumb;

        }
        return $res;
    }


}
